<?php
class EUpload extends CWidget {

	var $assets = '';
	var $options = array();
	var $model;
	var $name;
	var $type = 'input';
	
	/**
	 * Initializes the widget.
	 * This method is called by {@link CBaseController::createWidget}
	 * and {@link CBaseController::beginWidget} after the widget's
	 * properties have been initialized.
	 */
	public function init()
	{
		$this->assets = Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.upload.assets'));
		$cs = Yii::app()->getClientScript();
		$cs->registerCoreScript( 'jquery' );		
        $cs->registerCssFile( $this->assets.'/main.css' );
		$cs->registerScriptFile( $this->assets.'/ajaxupload.js' );
        
        $default = array(
        	'name'=>$this->name,
        	'show_result'=>true,
        	'show_queue'=>true,
        	'show_loader'=>true,
        );

		$this->options = array_merge($default, $this->options);
        $options = CJavaScript::encode($this->options);

		$cs->registerScript(__CLASS__.'#'.$this->id,"new AjaxUpload('#{$this->id}', {$options}) ;");

        parent::init();
	}

	/**
	 * Executes the widget.
	 * This method is called by {@link CBaseController::endWidget}.
	 */
	public function run()
	{
		$this->render('EUpload', array('id'=>$this->id, 'type'=>$this->type, 'options'=>$this->options));		
	}
	
	
}
?>